<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="com.beforesunrise.project.server.*" %>

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
  </head>

  <body>
  
			<!-- 적절한 곳에 이 렌더링 호출을 넣습니다. -->
	<script type="text/javascript">
	 (function() {
		var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
		po.src = 'https://apis.google.com/js/plusone.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
	})();
	
	function mapShowHide() {
//		var oIfr = document.getElementById('mapTest'); 
//		oIfr.style.display=(oIfr.style.display=='block')?'none':'block'; 
		
		var where = document.getElementById('where'); 
		var frm = document.getElementById('frm');
		var keyword = document.getElementById('keyword');
		frm.action='map.jsp?keyword='+where.value;
		keyword.value = where.value; 
		frm.submit(); 	
	}
	</script>   
	<form id='frm' action="map.jsp" method=get target="mapTest">
	<input type='hidden' id='keyword' name='keyword' value=''/>
	</form>
	<div id="header">	
	</div>
	<div id="container">
	<div id="innerContainer">
		<div id="left">
			<%
			    UserService userService = UserServiceFactory.getUserService();
			    User user = userService.getCurrentUser();
			    if (user != null) {
			%>
			<p>Hello, <%= user.getNickname() %>! (You can
			<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>
			<%
			    } else {
			%>
			<p>Hello!
			<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>
			to include your name with greetings you post.</p>
			<%
			    }
			%>
		</div>
		<div id="contents">
		<div id="contentsInnerSpace">
		    <form action="/sign" method="post">
			<div style="margin: 16px 0px">
				<div style="float: left;"><span id="streamTitle">Stream</span>  </div>
  				<div align="right"><input type="submit" value="Post Greeting"/></div>
			</div>
			<div id="editStream">
				<div id="Item">
		      	<textarea name="content" rows="3" cols="60" style="width:100%;"></textarea>
		    	</div>
			</div>
	      	<span id="streamTitle">What</span><br><input type="text" id="what" value='' style="width:100%"/><div style="height:7px"></div>
	      	<span id="streamTitle">Where</span><br><input type="text" id="where" value=''/>&nbsp<img src="images/MapPin.png" title="location" style="cursor:pointer" onclick="mapShowHide()"><br>
		    </form>
					
			<form id='gForm' method="post" onSubmit="return false;">
		    <iframe id="mapTest" name="mapTest" src="map.jsp" width="500" height="500" style="margin: 16px 21px 0 21px;">
		  		<p>Your browser does not support iframes.</p>
		   	</iframe>
		   	</form>
		   	<div style="border-top: 1px solid #DDD;"></div>

			<div id="ListStream">
				
			<%
			    PersistenceManager pm = PMF.get().getPersistenceManager();
			    String query = "select from " + Greeting.class.getName() + " order by date desc range 0,5";
			    List<Greeting> greetings = (List<Greeting>) pm.newQuery(query).execute();
			    if (greetings.isEmpty()) {
			%>
			<p>The guestbook has no messages.</p>
			<%
			    } else {
			        for (Greeting g : greetings) {
			            if (g.getAuthor() == null) {
			%>
			<p>An anonymous person wrote:</p>
			<%
			            } else {
			%>
			<p><b><%= g.getAuthor().getNickname() %></b> wrote:</p>
			<%
			            }
			%>
			<blockquote><%= g.getContent() %></blockquote>
			<%
			        }
			    }
			    pm.close();
			%>
			<!-- +1 버튼이 렌더링되기를 원하는 곳에 이 태그를 넣습니다. -->
			<g:plusone annotation="inline"></g:plusone>
							
			</div>
		   	<div style="margin:21px"></div>
		</div>
			</div>
			<div id="right">
			Friends
			</div>
		</div>

	</div>
	</div>
 
	<div id="footer">@2011 Before Sunrise - Younggi Ki, Chulho Choi, Inyoung Jang</div>	
  </body>
</html>
